package com.zdy.demo;

import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestThread2 extends Thread{
    private String url;
    private String name;

    public TestThread2(String url,String name){
        this.url = url;
        this.name = name;
    }

    public TestThread2() {

    }

    @Override
    public void run() {
        WebDownLoader webDownLoader = new WebDownLoader();
        webDownLoader.downLoader(url,name);
        System.out.println("下载了文件名为：" + name);

    }

    public static void main(String[] args) {
        //url 在网上随便找的，可能会失效，自己手动换一个即可
        TestThread2 t1 = new TestThread2("https://www.baidu.com/img/dong3_ce6e6a5ce66ab92f491f627981a2f77c.gif","图片1");
        TestThread2 t2 = new TestThread2("http://img95.699pic.com/photo/50155/6342.jpg_wh860.jpg!/both/590x400","图片2");
        TestThread2 t3 = new TestThread2("https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X3BuZy96eG9MYWVDSTI4U2dSNUVZTTBlY0UyT1VCdkZBZHo0TUhubFBEaGxjcmJNMnlueG0wWUpqNFBDTGxQS0FuUW1UeHpYTDVqVHlnYnRoM0lQOGVZRjVhZy82NDA?x-oss-process=image/format,png","图片3");
        t1.start();
        t2.start();
        t3.start();
    }
}
//创建下载器类
class WebDownLoader{
    public void downLoader(String url,String name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("IO 异常downLoader方法出现问题");
        }
    }
}
